﻿using System.Collections.Generic;
using System.Collections.Specialized;

namespace LogicProtocolAnalyzer
{
    static internal class SampleSettings
    {
        private const char SeparatorCharacter = '=';

        internal static StringCollection ToStringCollection(this IDictionary<string, string> data)
        {
            StringCollection collection = new StringCollection();
            if (data != null)
            {
                foreach (string key in data.Keys)
                {
                    collection.Add(string.Format("{0}={1}", key, data[key]));
                }
            }
            return collection;
        }

        internal static IDictionary<string, string> ToDictionary(this StringCollection data)
        {
            IDictionary<string, string> lookup = new Dictionary<string, string>();
            if (data != null)
            {
                foreach (string str in data)
                {
                    string key = str.Substring(0, str.IndexOf(SeparatorCharacter));
                    string value = str.Substring(key.Length + 1);
                    lookup.Add(key, value);
                }
            }
            return lookup;
        }
    }
}
